'use strict';
const express = require('express')
const bodyParser = require('body-parser');
const passport = require('passport')
const oauth2 = require('./oauth2');

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: false
}));


app.use(passport.initialize());

/**
 * grant_type: password
 * username: xx
 * password: xx
 * scope(可选): xx
 * 或者
 * grant_type: refresh_token
 * refresh_token: xx
 * scope(可选): xx
 */
app.post('/oauth/token',oauth2.token);


app.get('/api/user',oauth2.authenticate(),function(req,res){
	res.end('ok');
});

app.listen(3000, function(err) {
    if (err) {
        console.log(err);
    } else {
        console.log('server start at 3000');
    }
})